package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; 
import java.util.logging.Level;
import java.util.logging.Logger;
 
import entities.ResourceDeclaration;
import factory.DBConnectionFactory;

public class MySQLResourceDeclarationDAO extends ResourceDeclarationDAO{

	@Override
	public ArrayList<ResourceDeclaration> getResourceDeclaration() {
		 DBConnectionFactory myFactory = DBConnectionFactory.getInstance(DAOFactory.MYSQL);
		    Connection conn = myFactory.getConnection();
		    PreparedStatement pstmt3;
		     ArrayList<ResourceDeclaration> rds = new ArrayList<ResourceDeclaration>(); 
		     ResourceDeclaration rd = new ResourceDeclaration();  
	        try {
				pstmt3 = conn.prepareStatement("SELECT * FROM [ResourceDeclaration$]");
		        ResultSet rs = pstmt3.executeQuery();
		        while(rs.next()){
		        	rd=new ResourceDeclaration();
		        	rd.setProcessID(rs.getInt(1));
		        	rd.setResource(rs.getString(2));
		        	rd.setMaximum(rs.getInt(3));
		        	rds.add(rd);
		        }
			} catch (SQLException x) {
				// TODO Auto-generated catch block
				 Logger.getLogger(MySQLResourceDeclarationDAO.class.getName()).log(Level.SEVERE, null, x);
			} 	
		return rds;
	}

	@Override
	public String[] getResourceDeclarationCol() {
		// TODO Auto-generated method stub
		String[] str= {"ProcessID", "Resource", "Maximum"};
		return str;
	}

}
